<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>

    // 直接转，类似于给数据套了个引号
    // var num = 365;
    // var num = 365.789;
    // var num = -365.789;
    // var str = num.toString(); 
    // console.log(num); //365或者365.789或者-365.789
    // console.log(typeof num);// number
    // console.log(str);//365或者365.789或者-365.789
    // console.log(typeof str); //string

    //to.string不能转 null 和 undefined

    // 将数值转换成字符时，可以指定n小数位
    // var num = 365;
    // var num = 365.789;
    // var num = -365.789;
    // var str = num.toFixed(2);
    // console.log(num); //365或者365.789或者-365.789
    // console.log(typeof num); //number
    // console.log(str);  //365或者365.789或者-365.789
    // console.log(typeof str); //string

    // 给数据套了个引号
    console.log( String( "hello" ) ); //hello
    console.log( String( 123 ) ); //123
    console.log( String( NaN ) ); //NaN
    console.log( String( true ) ); //true
    console.log( String( false ) ); //false
    console.log( String( undefined ) ); //undefined
    console.log( String( null ) ); //null
    console.log( String( function(){} ) ); //function(){}
    // 将中括号换成了引号
    console.log( String( [] ) ); //空
    console.log( String( [3,6,4,2,1] ) ); //3,6,4,2,1
    console.log( String( [true, false] ) ); //true,false
    console.log( String( [{},{},{}] ) );//[object Object],[object Object],[object Object]
    
    // 花括号的对象转成："[object Object]"
    console.log( String( {name:"admin"} ) ); //[object Object]
    console.log( String( {} ) ); //[object Object]





</script>
</html>